# ============================================================
# * Copyright © hk. 2022-2025. All rights reserved.
# * File name: CMakeLists.txt
# * Author   : 苏木
# * Date     : 2025-05-22
# * Version  : 
# * Description: cmake version 3.16.3
# ============================================================
## https://cmake.com.cn/cmake/help/latest/guide/tutorial/index.html
## https://cmake.org/cmake/help/latest/

# 指定 CMake 的最低版本要求
# --------------------------------------------------
cmake_minimum_required(VERSION 3.10)


# 设置项目名称和使用的编程语言
# --------------------------------------------------
project(SPROJECT C)


# 指定可执行程序和源文件
# --------------------------------------------------
add_executable(app_demo.out main.c)

# break、continue 就和C语言中的作用一样
# --------------------------------------------------
message(STATUS "==> break")
set(i 1)
while(i LESS_EQUAL 5)
	message(STATUS "i = ${i}")
	if(i GREATER 2)
		break()
	endif()
	math(EXPR i "${i} + 1")
endwhile()
message("")

message(STATUS "==> continue")
set(i 1)
while(i LESS_EQUAL 5)
	math(EXPR i "${i} + 1")
	if(i LESS_EQUAL 2)
		continue()
	endif()
	message(STATUS "i = ${i}")
endwhile()
message("")

message(STATUS "==> break and continue")
foreach(outerVar IN ITEMS a b c)
	unset(s)
	foreach(innerVar IN ITEMS 1 2 3)
		# Stop inner loop once string s gets long
		list(APPEND s "${outerVar}${innerVar}")
		string(LENGTH s length)
		if(length GREATER 5)
			break()    # (1) 提前结束innerVar的循环。
		endif()

		# Do no more processing if outer var is "b"
		if(outerVar STREQUAL "b")
			continue() # (2) 结束当前innerVar的迭代，跳转至下一个迭代。
		endif()
		message("Processing ${outerVar}-${innerVar}")
	endforeach()
	message("Accumulated list: ${s}")
endforeach()
message("")
